<!DOCTYPE html>
<html lang="en">
  <head>
    <meta charset="UTF-8" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0" />
    <title>Document</title>
    <link rel="stylesheet" href="https://lib.baomitu.com/ol3/4.6.5/ol.css" />
    <script src="https://lib.baomitu.com/ol3/4.6.5/ol.js"></script>
  </head>
  <body>
    <div id="map" style="width: 100%; height: 100%"></div>
    <script>
      const gaode = new ol.layer.Tile({
        title: "高德地图",
        source: new ol.source.XYZ({
          url: "http://wprd0{1-4}.is.autonavi.com/appmaptile?lang=zh_cn&size=1&style=7&x={x}&y={y}&z={z}",
          wrapX: false,
        }),
      });
      const map = new ol.Map({
        target: "map",
        layers: [gaode],
        view: new ol.View({
          center: [114.3, 30.5],
          zoom: 10,
          projection: "EPSG:4326",
        }),
      });
      // 创建矢量数据源，加载外部 geojson
      const source = new ol.source.Vector({
        url: "data/map.geojson",
        format: new ol.format.GeoJSON(),
      });
      const layer = new ol.layer.Vector({
        source,
      });
      const style = new ol.style.Style({
        image: new ol.style.Circle({
          radius: 10,
          fill: new ol.style.Fill({
            color: "red",
          }),
        }),
      });
      // 把样式给图层的效果就是，这个图层中所有的元素，都会应用上这个样式。比如这个图层中加入了多个圆点，那么这些圆点的样式都是一样的
      layer.setStyle(style);
      map.addLayer(layer);
    </script>
  </body>
</html>
